<template>
  <div class="app-container">
    <el-card>
      <div slot="header" class="clearfix">
        <span>任务详情</span>
        <el-button style="float: right;" @click="$router.go(-1)">返回</el-button>
      </div>
      
      <el-descriptions :column="1" border>
        <el-descriptions-item label="任务名称">{{ task.task_name }}</el-descriptions-item>
        <el-descriptions-item label="填单人">{{ task.login_user }}</el-descriptions-item>
        <el-descriptions-item label="填单日期">{{ task.create_date }}</el-descriptions-item>
        <el-descriptions-item label="状态">
          <el-tag :type="task.exec_status === '成功' ? 'success' : 'danger'">
            {{ task.exec_status }}
          </el-tag>
        </el-descriptions-item>
      </el-descriptions>
      
      <el-button 
        type="primary" 
        style="margin-top: 20px"
        @click="downloadExcel"
      >
        下载Excel文件
      </el-button>
    </el-card>
  </div>
</template>

<script>
import request from '@/utils/request'

export default {
  name: 'FillformDetail',
  data() {
    return {
      task: {}
    }
  },
  created() {
    this.getTaskDetail()
  },
  methods: {
    getTaskDetail() {
      const taskId = this.$route.params.task_id
      request({
        url: `/smart/fillform/detail/${taskId}`,
        method: 'get'
      }).then(response => {
        this.task = response.data
      })
    },
    downloadExcel() {
      if (this.task.excel) {
        const link = document.createElement('a')
        link.href = `data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,${this.task.excel}`
        link.download = `${this.task.task_name}.xlsx`
        link.click()
      }
    }
  }
}
</script>